#!/usr/bin/env python
#-*- coding:utf-8 -*-
import dataselect
import tkinter as tk
from tkinter.font import Font
from tkinter.ttk import *
import tkinter.messagebox as mg

class gui:
    data = dataselect.Datamanage()
    type_group = False #查询结果是否按类型分组
    pos_group = False  #查询结果是否按部位分组
    order_asc = True  #查询结果按等级正序还是逆序
    relic_list = [] #圣遗物列表
    assemble_list = [] #人物列表
    weapon_pic_list = [] #武器列表
    select_box = ['%', '%', '%', '%','%', '%', '%', '%','%', '%', '%', '%','%', '%', '%', '%','%', '%'] #选中了哪个筛选条件
    relics_attribute = ['生命值','生命值百分比','攻击力','攻击力百分比','防御力','防御力百分比','暴击率','暴击伤害','元素精通','元素充能效率','治疗加成','物理伤害加成','岩元素伤害加成','风元素伤害加成','冰元素伤害加成','水元素伤害加成','火元素伤害加成','雷元素伤害加成']
    relics_name = ['全部', '昔日宗室之仪','苍白之火','千岩牢固','沉沦之心', '冰封迷途的勇士','炽烈的炎之魔女','渡过烈火的贤人','翠绿之影','被怜爱的少女', '染血的骑士道','流浪大地的乐团', '角斗士的终幕礼','平息鸣雷的尊者']
    relics_detailname = ['无垢之花', '贤医之羽', '停摆之刻','超越之盏','嗤笑之面', '勋绩之花', '昭武翎羽','金铜时晷','盟誓金爵','将帅兜鍪','饰金胸花', '追忆之风','坚铜罗盘','沉波之盏','酒渍船帽','历经风雪的思念', '摧冰而行的执望','冰雪故园的终期','遍结寒霜的傲骨',  '破冰踏雪的回音', '魔女的炎之花', '魔女常燃之羽','魔女破灭之时', '魔女的心之火','焦灼的魔女帽', '渡火者的决绝', '渡火者的解脱','渡火者的煎熬','渡火者的醒悟', '渡火者的智慧','平雷之心','平雷之羽','平雷之冠','平雷之刻', '平雷之器', '猎人青翠的箭羽','野花记忆的绿野',  '翠绿猎人的笃定', '翠绿猎人的容器',  '翠绿的猎人之冠','远方的少女之心', '少女飘摇的思念','少女苦短的良辰','少女片刻的闲暇','少女易逝的芳颜', '染血的铁之心', '染血的黑之羽','骑士染血之时','染血骑士之杯', '染血的铁假面','宗室之花', '宗室之翎','宗室时计','宗室银瓮','宗室面具','乐团的晨光','琴师的箭羽','终幕的时计','吟游者之壶', '指挥的礼帽','角斗士的留恋', '角斗士的归宿','角斗士的希冀', '角斗士的酣醉','角斗士的凯旋']
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      
    relics_pos = {'无垢之花': 'flower', '勋绩之花': 'flower', '饰金胸花': 'flower', '历经风雪的思念': 'flower', '魔女的炎之花': 'flower', '渡火者的决绝': 'flower', '平雷之心': 'flower', '野花记忆的绿野': 'flower', '远方的少女之心': 'flower', '染血的铁之心': 'flower', '宗室之花': 'flower', '乐团的晨光': 'flower', '角斗士的留恋': 'flower', '贤医之羽': 'feather', '昭武翎羽': 'feather', '追忆之风': 'feather', '摧冰而行的执望': 'feather','平雷之羽' : 'feather', '魔女常燃之羽': 'feather', '渡火者的解脱': 'feather', '猎人青翠的箭羽': 'feather', '少女飘摇的思念': 'feather', '染血的黑之羽': 'feather', '琴师的箭羽': 'feather', '角斗士的归宿': 'feather','宗室之翎' : 'feather', '平雷之刻': 'sand', '停摆之刻': 'sand', '金铜时晷': 'sand', '坚铜罗盘': 'sand', '冰雪故园的终期': 'sand', '魔女破灭之时': 'sand', '渡火者的煎熬': 'sand', '翠绿猎人的笃定': 'sand', '少女苦短的良辰': 'sand', '骑士染血之时': 'sand', '宗室时计': 'sand', '终幕的时计': 'sand', '角斗士的希冀': 'sand', '超越之盏': 'cup', '盟誓金爵': 'cup', '沉波之盏': 'cup', '平雷之器': 'cup', '遍结寒霜的傲骨': 'cup', '魔女的心之火': 'cup', '渡火者的醒悟': 'cup', '翠绿猎人的容器': 'cup', '少女片刻的闲暇': 'cup', '染血骑士之杯': 'cup', '宗室银瓮': 'cup', '吟游者之壶': 'cup', '角斗士的酣醉': 'cup', '平雷之冠': 'head', '嗤笑之面': 'head', '将帅兜鍪': 'head', '酒渍船帽': 'head', '破冰踏雪的回音': 'head', '焦灼的魔女帽': 'head', '渡火者的智慧': 'head', '翠绿的猎人之冠': 'head', '少女易逝的芳颜': 'head', '染血的铁假面': 'head', '宗室面具': 'head', '指挥的礼帽': 'head', '角斗士的凯旋': 'head'}
    relics_setname = {'无垢之花':'苍白之火', '贤医之羽':'苍白之火', '停摆之刻':'苍白之火','超越之盏':'苍白之火','嗤笑之面':'苍白之火', '勋绩之花':'千岩牢固', '昭武翎羽':'千岩牢固','金铜时晷':'千岩牢固','盟誓金爵':'千岩牢固','将帅兜鍪':'千岩牢固','饰金胸花':'沉沦之心', '追忆之风':'沉沦之心','坚铜罗盘':'沉沦之心','沉波之盏':'沉沦之心','酒渍船帽':'沉沦之心','历经风雪的思念':'冰封迷途的勇士', '摧冰而行的执望':'冰封迷途的勇士','冰雪故园的终期':'冰封迷途的勇士','遍结寒霜的傲骨':'冰封迷途的勇士', '破冰踏雪的回音':'冰封迷途的勇士', '魔女的炎之花':'炽烈的炎之魔女', '魔女常燃之羽':'炽烈的炎之魔女','魔女破灭之时':'炽烈的炎之魔女', '魔女的心之火':'炽烈的炎之魔女','焦灼的魔女帽':'炽烈的炎之魔女', 
                      '渡火者的决绝':'渡过烈火的贤人', '渡火者的解脱':'渡过烈火的贤人','渡火者的煎熬':'渡过烈火的贤人','渡火者的醒悟':'渡过烈火的贤人', '渡火者的智慧':'渡过烈火的贤人','平雷之心':'平息鸣雷的尊者','平雷之羽':'平息鸣雷的尊者','平雷之冠':'平息鸣雷的尊者','平雷之刻':'平息鸣雷的尊者', '平雷之器':'平息鸣雷的尊者', 
                      '猎人青翠的箭羽':'翠绿之影','野花记忆的绿野':'翠绿之影',  '翠绿猎人的笃定':'翠绿之影', '翠绿猎人的容器':'翠绿之影',  '翠绿的猎人之冠':'翠绿之影','远方的少女之心':'被怜爱的少女', '少女飘摇的思念':'被怜爱的少女','少女苦短的良辰':'被怜爱的少女','少女片刻的闲暇':'被怜爱的少女','少女易逝的芳颜':'被怜爱的少女', 
                      '染血的铁之心':'染血的骑士道', '染血的黑之羽':'染血的骑士道','骑士染血之时':'染血的骑士道','染血骑士之杯':'染血的骑士道', '染血的铁假面':'染血的骑士道','宗室之花':'昔日宗室之仪', '宗室之翎':'昔日宗室之仪','宗室时计':'昔日宗室之仪','宗室银瓮':'昔日宗室之仪','宗室面具':'昔日宗室之仪',
                      '乐团的晨光':'流浪大地的乐团','琴师的箭羽':'流浪大地的乐团','终幕的时计':'流浪大地的乐团','吟游者之壶':'流浪大地的乐团', '指挥的礼帽':'流浪大地的乐团','角斗士的留恋':'角斗士的终幕礼', '角斗士的归宿':'角斗士的终幕礼','角斗士的希冀':'角斗士的终幕礼', '角斗士的酣醉':'角斗士的终幕礼','角斗士的凯旋':'角斗士的终幕礼'}
    
    
    relics_percentage = ['生命值百分比','攻击力百分比','防御力百分比','暴击率','暴击伤害','元素充能效率','治疗加成','物理伤害加成','岩元素伤害加成','风元素伤害加成','冰元素伤害加成','水元素伤害加成','火元素伤害加成','雷元素伤害加成']
    weapon_list = ['阿莫斯之弓', '拨乱月白经津', '不灭月华', '苍古自由之誓', '尘世之锁', '赤角石溃杵', '冬极白星', '飞雷之弦振', '风鹰剑', '贯虹之槊', '和璞鸢', '护摩之杖', '狼的末路', '磐岩结绿', '神乐之真意', '四风原典', '松籁响起之时', '薙草之稻光', '天空之傲', '天空之脊', '天空之卷', '天空之刃', '天空之翼', '无工之剑', '雾切之回光', '息灾', '终末嗟叹之诗', '斫峰之刃']
    character_list = ['阿贝多', '八重神子', '达达利亚', '迪卢克', '枫原万叶', '甘雨', '胡桃', '荒泷一斗', '可莉', '刻晴', '雷电将军', '莫娜', '七七', '琴', '珊瑚宫心海', '申鹤', '神里绫华', '神里绫人', '温迪', '宵宫', '魈', '优菈', '钟离']
    attribute_list = ['生命值上限', '攻击力', '防御力', '元素精通', '暴击率','暴击伤害', '治疗加成', '元素充能效率','火元素伤害加成','水元素伤害加成','雷元素伤害加成','风元素伤害加成','冰元素伤害加成','岩元素伤害加成','物理伤害加成']
    def __init__(self):
        self.top = tk.Tk()
        self.top.title('hutao')
        self.top.iconbitmap("E:/picture/hutao512.ico")
        self.top.geometry('1126x672')
        self.top.withdraw()
        
        style = Style()

        self.Frame1 = tk.LabelFrame(self.top, text='', background='#e0ffcf', font=('宋体',9))
        self.Frame1.place(relx=0.128, rely=-0.001, relwidth=1.23, relheight=0.160)
        
        self.relics_title = tk.Label(self.Frame1, anchor = 'n', text = '圣遗物管理', font = ('微软雅黑', 20, 'bold'), bg = '#e0ffcf')
        self.relics_title.place(relx = 0.03, rely = 0.2)

    

        self.Frame2 = tk.LabelFrame(self.top,background='#8080FF', font=('宋体',9))
        self.Frame2.place(relx=0., rely=-0.01, relwidth=0.129, relheight=1.19)
        
    
        #颜色改回来要
        self.Frame3 = tk.LabelFrame(self.top, text='',font=('宋体',9),bg = '#FFFFFF')
        self.Frame3.place(relx=0.128, rely=0.140, relwidth=0.874, relheight=0.865)
        
        #清空按钮
        style.configure('self.dele_option.TButton',background='#FFFFFF', font=('宋体',9))
        self.dele_option = Button(self.Frame1, text='清空', command=self.dele_option_Cmd, style='self.dele_option.TButton',cursor = 'hand2')
        self.dele_option.place(relx=0.624, rely=0.18, relwidth=0.058, relheight=0.461)
        
        #筛选按钮
        style.configure('self.sel_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.sel_button = Button(self.Frame1, text='筛选', command=self.sel_button_Cmd, style='self.sel_button.TButton',cursor = 'hand2')
        self.sel_button.place(relx=0.433, rely=0.18, relwidth=0.058, relheight=0.461)
        
        #排序按钮
        style.configure('order_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.order_text = tk.StringVar()
        self.order_text.set('等级逆序')
        self.order_button = Button(self.Frame1, textvariable = self.order_text, command=lambda:self.change_order_cmd(style), style='order_button.TButton',cursor = 'hand2')
        self.order_button.place(relx=0.3375, rely=0.18, relwidth=0.058, relheight=0.461)
        
        #按类型分组按钮
        style.configure('type_group_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.type_group_button = Button(self.Frame1, text = '按类型分组', command=lambda:self.type_group_cmd(style), style='type_group_button.TButton',cursor = 'hand2')
        self.type_group_button.place(relx=0.242, rely=0.18, relwidth=0.058, relheight=0.461)
        
        #按部位分组按钮
        style.configure('pos_group_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.pos_group_button = Button(self.Frame1, text = '按部位分组', command=lambda:self.pos_group_cmd(style), style='pos_group_button.TButton',cursor = 'hand2')
        self.pos_group_button.place(relx=0.1465, rely=0.18, relwidth=0.058, relheight=0.461)
        
        '''
        style.configure('self.Label_1.TLabel',anchor='w', background='#e0ffcf', font=('宋体',9))
        self.Label_1 = Label(self.Frame1, style='self.Label_1.TLabel')
        self.Label_1.place(relx=0.006, rely=0.09, relwidth=0.168, relheight=1.18)
        '''
    
        #左上角图片
        self.hutao_pic= tk.PhotoImage( file =r"E:\picture\hutao.png")
        self.hutao_pic = self.hutao_pic.subsample( 6 , 6)
        self.Label_2 = Label(self.Frame2, anchor='center', background='#2cd3e9', image = self.hutao_pic)
        self.Label_2.place(relx=-0.089, rely=0, relwidth=1.214, relheight=0.125)
    
        #左侧圣遗物按钮
        self.yuetuan_pic = tk.PhotoImage( file = r"E:\picture\yuetuan.png")
        self.yuetuan_pic = self.yuetuan_pic.subsample( 1 , 1)  
        self.Relics_button = tk.Button(self.Frame2,image = self.yuetuan_pic,command=self.Relics_button_Cmd,bg = '#8080FF',activebackground = '#8080FF',cursor = 'hand2')
        self.Relics_button.place(relx=0.276, rely=0.156, relwidth=0.503, relheight=0.079)
        
        #左侧武器按钮
        self.wuqie_pic = tk.PhotoImage( file = r"E:\picture\panyan.png")
        self.wuqie_pic = self.wuqie_pic.subsample(7,7)
        self.weapon_button = tk.Button(self.Frame2, text='Command2', image = self.wuqie_pic, command=self.weapon_button_Cmd,bg = '#8080FF',activebackground = '#8080FF',cursor = 'hand2')
        self.weapon_button.place(relx=0.276, rely=0.266, relwidth=0.503, relheight=0.079)
        
        #左侧人物按钮
        self.shenli_pic = tk.PhotoImage( file = r"E:\picture\shenli.png")
        self.shenli_pic = self.shenli_pic.subsample(3,3)
        self.character_button = tk.Button(self.Frame2, text='Command3', command=self.character_button_Cmd, image = self.shenli_pic,bg = '#8080FF',activebackground = '#8080FF',cursor = 'hand2')
        self.character_button.place(relx=0.276, rely=0.376, relwidth=0.503, relheight=0.079)

        #存放单个圣遗物框架的总框架
        #画布用来使框架Frame4框架滚动
        self.canvas_1 = tk.Canvas(self.Frame3)
        self.canvas_1.place(relx=0., rely=0., relwidth=0.984, relheight=1)
        #圣遗物界面滚动条
        self.VScroll_1 = tk.Scrollbar(self.Frame3,orient="vertical",command=self.canvas_1.yview)
        self.VScroll_1.pack(side='right',fill='y')
        self.canvas_1.configure(yscrollcommand=self.VScroll_1.set) #绑定滚动条和画布
        #存放圣遗物框架的框架,在画布上创建
        self.Frame4 = tk.Frame(self.canvas_1)
        self.Frame4.pack()
        #将Frame4添加到canvas_1上
        self.canvas_1.create_window((0,0),window = self.Frame4, anchor="nw")
        self.Frame4.bind("<Configure>",self.change_VScroll_1) #绑定框架和滚动条
        
        
        #圣遗物筛选子窗口
        self.relics_filter_win = tk.Toplevel()
        self.relics_filter_win.geometry('300x390')
        self.relics_filter_win.title('属性筛选')
        self.relics_filter_win.iconbitmap("E:/picture/hutao512.ico")
        self.relics_filter_win.protocol("WM_DELETE_WINDOW", lambda:self.check_retrieval(style))
        self.relics_filter_win.withdraw()#隐藏窗口
        #0或者1，选中为1,0或者1,0,1,0,1~~~
        self.CheckVar = [] 
        #复选框控件,选择圣遗物词条
        self.retrieval = []
        self.attribute_len = len(self.relics_attribute)
        half_attri_len = len(self.relics_attribute) // 2
        for i in range(self.attribute_len):
            self.CheckVar.append(tk.IntVar())
            self.retrieval.append(tk.Checkbutton(self.relics_filter_win,text=self.relics_attribute[i] ,font=('微软雅黑', 9,'bold'),variable = self.CheckVar[i],onvalue=1,offvalue=0))
            if (i < half_attri_len):
                self.retrieval[i].grid(row = i + 2, sticky = "w", padx = 20, pady = 3)
            else:
                self.retrieval[i].grid(row = i - half_attri_len + 2, column = 1,sticky = "w", padx = 20, pady = 3)
        #下拉菜单控件，选择圣遗物名称
        self.select_relics_box = Combobox(self.relics_filter_win, width = 15)
        self.select_relics_box['value'] = self.relics_name
        self.select_relics_box.grid(row = 0, column = 1, sticky = "w", pady = 5)
        self.select_relics_box.current(0)
        #下拉菜单控件，选择圣遗物位置
        self.select_pos_box = Combobox(self.relics_filter_win, width = 15)
        self.select_pos_box['value'] = ['全部', '花', '羽毛', '沙漏', '杯子', '头盔']
        self.select_pos_box.grid(row = 1, column = 1, sticky = "w", pady = 5)
        self.select_pos_box.current(0)
        #下拉菜单控件说明，选择类别
        self.select_relics_label = tk.Label(self.relics_filter_win, text = '类别', fg = 'gray', font = ('微软雅黑', 10, 'bold'))
        self.select_relics_label.grid(row = 0, column = 0)
        #下拉菜单控件说明，选择位置
        self.select_pos_label = tk.Label(self.relics_filter_win, text = '部位', fg = 'gray', font = ('微软雅黑', 10, 'bold'))
        self.select_pos_label.grid(row = 1, column = 0)
        
        
        #添加圣遗物窗口
        self.relics_add_win = tk.Toplevel()
        self.relics_add_win.geometry('500x500')
        self.relics_add_win.title('属性选择')
        self.relics_add_win.iconbitmap("E:/picture/hutao512.ico")
        self.relics_add_win.protocol("WM_DELETE_WINDOW", self.relics_add_win.withdraw)
        self.relics_add_win.withdraw()
        #标签
        self.relics_add_label = tk.Label(self.relics_add_win, text = '添加圣遗物', justify = tk.LEFT, font = ('微软雅黑', 15,'bold'))
        self.relics_add_label.grid(row = 0, column = 0, sticky = 'w', padx = 60, pady = 15)
        #圣遗物名称选择下拉控件
        self.relics_addname_box = Combobox(self.relics_add_win)
        self.relics_addname_box['value'] = self.relics_detailname
        self.relics_addname_box.grid(row = 1, column = 1, sticky = 'nw', pady = 3)
        self.relics_addname_box.current(0)
        #下拉控件标签
        self.relics_addname_label = tk.Label(self.relics_add_win, anchor = 'e', text = '圣遗物', fg = 'gray', justify = tk.LEFT, font = ('微软雅黑', 11,'bold'))
        self.relics_addname_label.grid(row = 1, column = 0, sticky = 'nw', pady = 3, padx = 60)
        #圣遗物等级选择输入框
        self.relics_addlevel_spin = tk.Spinbox(self.relics_add_win,from_=0,to=20, increment=1,width = 21,bg='#FFFFFF')
        self.relics_addlevel_spin.grid(row = 2, column = 1, sticky = 'nw', pady = 3)
        #等级选择标签
        self.relics_addlevel_label = tk.Label(self.relics_add_win, anchor = 'e', text = '等级', fg = 'gray', justify = tk.LEFT, font = ('微软雅黑', 11,'bold'))
        self.relics_addlevel_label.grid(row = 2, column = 0, sticky = 'nw', pady = 3, padx = 60)
        #圣遗物主词条下拉控件
        self.relics_mainname_box = Combobox(self.relics_add_win)
        self.relics_mainname_box['value'] = self.relics_attribute
        self.relics_mainname_box.grid(row = 3, column = 1, sticky = 'nw', pady = 3)
        self.relics_mainname_box.current(0)
        #圣遗物主词条标签
        self.relics_mainname_label = tk.Label(self.relics_add_win,anchor = 'e', text = '主词条名', fg = 'gray', justify = tk.LEFT, font = ('微软雅黑', 11,'bold') )
        self.relics_mainname_label.grid(row = 3, column = 0, sticky = 'nw', pady = 3, padx = 60)
        #圣遗物主词条数值输入框
        self.relics_mainvalue_entry = tk.Entry(self.relics_add_win, width = 23, bg = '#FFFFFF')
        self.relics_mainvalue_entry.grid(row = 4, column = 1, sticky = 'nw', pady = 3)
        self.relics_mainvalue_entry.insert(0,'4780')
        #圣遗物主词条数值标签
        self.relics_mainvalue_label = tk.Label(self.relics_add_win,anchor = 'e', text = '主词条值', fg = 'gray', justify = tk.LEFT, font = ('微软雅黑', 11,'bold') )
        self.relics_mainvalue_label.grid(row = 4, column = 0, sticky = 'nw', pady = 3, padx = 60)
        #圣遗物副词条标签
        self.relics_sub_label = tk.Label(self.relics_add_win, text = '副词条', justify = tk.LEFT, font = ('微软雅黑', 12,'bold'))
        self.relics_sub_label.grid(row = 5, column = 0,  sticky = 'w', padx = 60, pady = 10)
        #添加副词条按钮
        self.relics_subadd_button = tk.Button(self.relics_add_win,relief = 'ridge',text='添加副词条', command=self.relics_subadd,background='#FFFFFF', font=('宋体',9),cursor = 'hand2')
        self.relics_subadd_button.place(relx=0.11, rely=0.88, relwidth=0.15, relheight=0.08)
        #添加副词条属性标签
        self.relics_subname_label = tk.Label(self.relics_add_win, text = '属性名', fg = 'gray', justify = tk.LEFT, font = ('微软雅黑', 11,'bold'))
        self.relics_subname_label.place(relx = 0.29, rely = 0.47)
        self.relics_subvalue_label = tk.Label(self.relics_add_win, text = '属性值', fg = 'gray', justify = tk.LEFT, font = ('微软雅黑', 11,'bold'))
        self.relics_subvalue_label.place(relx = 0.51, rely = 0.47)
        #副词条属性
        self.relics_sub_list = []
        for i in range(4):
            relics_sub_dic = {}
            relics_sub_dic['show'] = False
            relics_sub_dic['relics_sub_frame'] = tk.Frame(self.relics_add_win)
            relics_sub_dic['relics_subname_box'] = Combobox(relics_sub_dic['relics_sub_frame'], width = 12)
            relics_sub_dic['relics_subname_box']['value'] = self.relics_attribute[:10]
            relics_sub_dic['relics_subname_box'].current(0)
            relics_sub_dic['relics_subname_box'].pack(side = 'left')
            relics_sub_dic['relics_subvalue_entry'] = tk.Entry(relics_sub_dic['relics_sub_frame'],width = 10, bg = '#FFFFFF')
            relics_sub_dic['relics_subvalue_entry'].pack(side = 'left')
            self.relics_sub_list.append(relics_sub_dic)
        self.relics_sub_list[0]['relics_subdele_button'] = tk.Button(self.relics_sub_list[0]['relics_sub_frame'],relief = 'ridge',text='删除',command = lambda:self.relics_sub_dele(0), background='#FFFFFF', font=('宋体',9),cursor = 'hand2')
        self.relics_sub_list[0]['relics_subdele_button'].pack(side = 'left')
        self.relics_sub_list[1]['relics_subdele_button'] = tk.Button(self.relics_sub_list[1]['relics_sub_frame'],relief = 'ridge',text='删除',command = lambda:self.relics_sub_dele(1), background='#FFFFFF', font=('宋体',9),cursor = 'hand2')
        self.relics_sub_list[1]['relics_subdele_button'].pack(side = 'left')
        self.relics_sub_list[2]['relics_subdele_button'] = tk.Button(self.relics_sub_list[2]['relics_sub_frame'],relief = 'ridge',text='删除',command = lambda:self.relics_sub_dele(2), background='#FFFFFF', font=('宋体',9),cursor = 'hand2')
        self.relics_sub_list[2]['relics_subdele_button'].pack(side = 'left')
        self.relics_sub_list[3]['relics_subdele_button'] = tk.Button(self.relics_sub_list[3]['relics_sub_frame'],relief = 'ridge',text='删除',command = lambda:self.relics_sub_dele(3), background='#FFFFFF', font=('宋体',9),cursor = 'hand2')
        self.relics_sub_list[3]['relics_subdele_button'].pack(side = 'left')
        #属性保存按钮
        self.relics_save_button = tk.Button(self.relics_add_win,relief = 'ridge',text='保存',bg = '#409eff',fg = '#FFFFFF', command=lambda:self.relics_save(style),font=('宋体',9,'bold'),cursor = 'hand2')
        self.relics_save_button.place(relx=0.78, rely=0.88, relwidth=0.15, relheight=0.08)
        #添加圣遗物按钮
        style.configure('self.add_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.add_button = Button(self.Frame1, text='+ 添加', command=self.relics_add_win.deiconify, style='self.add_button.TButton',cursor = 'hand2')
        self.add_button.place(relx=0.531, rely=0.18, relwidth=0.058, relheight=0.461)
        #调用人物界面
        self.character_interface(style)
        #调用武器界面
        self.weapon_Interface(style)
        #调用登录窗口
        
        self.login_window(style)
        
       
    #登录界面
    def login_window(self, style):
        self.login_win = tk.Toplevel()
        # 设置窗口大小变量
        width = 400
        height = 190
        # 窗口居中，获取屏幕尺寸以计算布局参数，使窗口居屏幕中央
        screenwidth = self.login_win.winfo_screenwidth()
        screenheight = self.login_win.winfo_screenheight()
        size_geo = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2)
        self.login_win.geometry(size_geo)
        #标题
        self.login_win.title("登录")
        self.login_win.iconbitmap("E:/picture/hutao512.ico")
        self.login_win.protocol("WM_DELETE_WINDOW", self.login_quit)
        #框架隔开
        self.blank_frame = tk.Frame(self.login_win)
        self.blank_frame.grid(row = 0, column = 0, rowspan = 4, ipadx = 38)
         # 将俩个标签分别布置在第一行、第二行
        self.zhanghao_label = tk.Label(self.login_win, text="账号:", font = ('微软雅黑', 10)).grid(row=0, column = 1, padx = 3, pady = 5, sticky = 'w')
        self.mima_label = tk.Label(self.login_win, text="密码:",font = ('微软雅黑', 10)).grid(row=1, column = 1, padx = 3, pady = 5,sticky = 'w')
        self.server_label = tk.Label(self.login_win, text="服务器:", font = ('微软雅黑', 10)).grid(row=2, column = 1, padx = 3, pady = 5,sticky = 'w')
        self.port_label = tk.Label(self.login_win, text="端口:", font = ('微软雅黑', 10)).grid(row=3, column = 1, padx = 3, pady = 5,sticky = 'w')
        
        # 创建输入框控件
        self.e1 = tk.Entry(self.login_win)
        # 以 * 的形式显示密码
        self.e2 = tk.Entry(self.login_win,show='*')
        self.e3 = tk.Entry(self.login_win)
        self.e4 = tk.Entry(self.login_win)
        self.e1.grid(row=0, column=2,  pady=5, sticky = 'w')
        self.e2.grid(row=1, column=2,  pady=5, sticky = 'w')
        self.e3.grid(row=2, column=2,  pady=5, sticky = 'w')
        self.e4.grid(row=3, column=2,  pady=5, sticky = 'w')

        # 使用 grid()的函数来布局，并控制按钮的显示位置
        self.login_button = tk.Button(self.login_win,relief = 'ridge',text='登录',bg = '#FFFFFF',command = lambda:self.login_commit(style), cursor = 'hand2', font = ('微软雅黑', 10))
        self.quit_button = tk.Button(self.login_win, relief = 'ridge',text="退出", bg = '#FFFFFF',command = self.login_quit, cursor = 'hand2', font = ('微软雅黑', 10))
        self.login_button.grid(row=4, column=1, padx=10, pady=5, ipadx = 15, sticky ="w")
        self.quit_button.grid(row=4, column=2, padx=15, pady=5, ipadx = 15, sticky ="e")

        
    #确认登录    
    def login_commit(self, style):
        if self.data.login_func(self.e1.get(),self.e2.get(),self.e3.get(),self.e4.get()):
            
            #同步数据库
            #self.update_select(style)
            self.initialize_assemble(style)
            #显示武器
            weapon_nane_list = self.data.select_weapon()
            for i in range(len(weapon_nane_list)):
                self.add_weapon(weapon_nane_list[i][0])
            #销毁登录窗口,显示应用主窗口
            self.top.deiconify()
            self.login_win.destroy()  
        else:
            mg.showerror(title='ERROR', message='登录信息有误')
            self.e1.delete(0, tk.END)
            self.e2.delete(0, tk.END)
            self.e3.delete(0, tk.END)
            self.e4.delete(0, tk.END)
    #取消登录    
    def login_quit(self):
        self.top.quit()
        
    #从数据库查询并初始化角色装配信息
    def initialize_assemble(self, style):
        assemble_data = self.data.select_assemble()
        for i in range(len(assemble_data)):
            #添加角色装配框架
            self.add_character_frame(assemble_data[i][0], style)
            #角色显示圣遗物
            for j in range(4):
                if assemble_data[i][j + 2] != None:
                    pos, detailName = self.data.select_relics_byid(assemble_data[i][j + 2])
                    self.assemble_relics_visable(i, detailName, pos)
            #角色显示武器
            if assemble_data[i][1] != None:
                self.assemble_weapon_visable(i, assemble_data[i][1])
        #在角色添加复选框中移除已有的角色
        self.remove_character_box()  
               
    #添加圣遗物图框
    #TODO:添加id信息
    def add_button_Cmd(self, attri_dic, style, event=None):
        new_relic = {}
        '''
        attri_dic['detailName']
        attri_dic['level']
        attri_dic['mainTag_name']
        attri_dic['mainTag_value']
        attri_dic['Tag1_value']
        '''
        new_relic['id'] = attri_dic['id']
        new_relic['num'] = len(self.relic_list) + 1 #列表中的第几个元素
        new_relic['detailName'] = attri_dic['detailName']
        new_relic['pos'] = attri_dic['pos']
        new_relic['Frame'] = tk.LabelFrame(self.Frame4, bg='#c4723a', bd = 0,height = '150', width = '190')
        new_relic['grid_row'] = len(self.relic_list) // 4
        new_relic['grid_column'] = len(self.relic_list) % 4
        new_relic['Frame'].grid(row = new_relic['grid_row'],column = new_relic['grid_column'], sticky = "w",padx = 10, pady = 10)
        sub_attri = ""
        for i in range(4):
            if attri_dic['Tag_name' + str(i)]:
                if attri_dic['Tag_name' + str(i)] in self.relics_percentage:
                    value = str(round(float(attri_dic['Tag_value' + str(i)]) * 100,1))
                    sub_attri = sub_attri + "· " + attri_dic['Tag_name' + str(i)] + value + '%\n'
                else:
                    value = str(round(float(attri_dic['Tag_value' + str(i)])))
                    sub_attri = sub_attri + "· " + attri_dic['Tag_name' + str(i)] + value + '\n'
        sub_attri.strip()
        
        #sub_attri = "· 元素充能效率4.5%\n· 生命值4.7%\n· 攻击力4.7%\n· 暴击率10.5%"
        new_relic['sub_attri_label'] = tk.Label(new_relic['Frame'], anchor='w', background='#FFFFFF',text = sub_attri, font=('宋体',9),justify = tk.LEFT)
        new_relic['sub_attri_label'].place(relx=0., rely=0.55, relwidth=1, relheight=0.448)
        
        if attri_dic['mainTag_name'] in self.relics_percentage:
            value = str(round(float(attri_dic['mainTag_value'])* 100,1))
            main_attri = attri_dic['mainTag_name']+'\n\n'+ value + '%'
        else:
            value = str(round(float(attri_dic['mainTag_value'])))
            main_attri = attri_dic['mainTag_name']+'\n\n'+value
        new_relic['main_attri_label'] = tk.Label(new_relic['Frame'],anchor='w', bg='#c4723a', fg = '#FFFFFF', font=('宋体',9, 'bold'),text = main_attri, justify = tk.LEFT)
        new_relic['main_attri_label'].place(relx=0.041, rely=0.22, relwidth=0.5, relheight=0.3)
        
        new_relic['level_label'] = tk.Label(new_relic['Frame'], text = str(attri_dic['level']),anchor='center', background='#FFFFFF', font=('宋体',10))
        new_relic['level_label'].place(relx=0.052, rely=0.032, relwidth=0.144, relheight=0.12)
        
        new_relic['formore_button'] = tk.Menubutton(new_relic['Frame'], text='...', relief = 'ridge',activebackground = '#c4723a',font=('宋体',10,'bold'),bg = '#c4723a',bd = 0, cursor = 'hand2')
        new_relic['filemenu']=tk.Menu(new_relic['formore_button'],tearoff = False)
        
        
        new_relic['filemenu'].add_command(label = '装备', command = lambda:self.relics_up(new_relic['id'], new_relic['num'], new_relic['pos'], style))
        new_relic['filemenu'].add_command(label = '删除',command = lambda:self.formore_button_Cmd(new_relic['id'],new_relic['num']))
        
        
        new_relic['formore_button'].config(menu = new_relic['filemenu'])
        if attri_dic['equipped'] == None:
            new_relic['formore_button'].place(relx=0.864, rely=0, relwidth=0.13, relheight=0.08)
                
        new_relic['name_label'] = tk.Label(new_relic['Frame'], text = attri_dic['detailName'],anchor='w', bg='#c4723a', fg = '#FFFFFF',font=('宋体',10,'bold'),justify = tk.LEFT)
        new_relic['name_label'].place(relx=0.195, rely=0.032, relwidth=0.53, relheight=0.12)
        
        #图片
        new_relic['shengyi_pic'] = tk.PhotoImage(file = 'E:/picture/relics/' + attri_dic['detailName'] + '.png' )
        new_relic['shengyi_pic'] = new_relic['shengyi_pic'].subsample(2,2)
        new_relic['relic_pic_label'] = tk.Label(new_relic['Frame'],image = new_relic['shengyi_pic'],anchor='n', background='#c4723a', font=('宋体',9))
        new_relic['relic_pic_label'].place(relx=0.691, rely=0.15, relwidth=0.293, relheight=0.331)
        self.Frame4.update() #更新框架大小
        self.relic_list.append(new_relic)
    
    
    #改变排序顺序
    #TODO:按筛选条件到数据库重新查询，并按等级排序，更新前端
    #finish
    def change_order_cmd(self, style, event = None):
        if (self.order_text.get() == '等级正序'):
            self.order_text.set('等级逆序')
            self.order_asc = True
        else:
            self.order_text.set('等级正序')
            self.order_asc = False
        self.update_select(style)
            
    def type_group_cmd(self, style):
        if self.type_group == False:
            self.type_group = True
            self.pos_group = False
        else:
            self.type_group = False
        self.update_select(style)
            
    def pos_group_cmd(self, style):
        if self.pos_group == False:
            self.pos_group = True
            self.type_group = False
        else:
            self.pos_group = False
        self.update_select(style)
    
    #查询数据库并更新前端圣遗物显示
    def update_select(self,style):
        attri_dic_list = self.data.screen_relics(self.select_box, self.select_relics_box.get(), self.select_pos_box.get(),self.order_asc,self.type_group,self.pos_group)
        #更改前端显示
        for i in range(len(self.relic_list)):
            self.relic_list[i]['Frame'].destroy()
        self.relic_list.clear()    
        for i in range(len(attri_dic_list)):
            self.add_button_Cmd(attri_dic_list[i], style)
    
    #检查筛选的属性是否符合
    #TODO：按筛选条件查询
    #finish
    def check_retrieval(self, style):
        all_num = 0
        #更新词条筛选条件
        self.select_box.clear()
        for i in range(self.attribute_len):
            if self.CheckVar[i].get() == 1:
                all_num += 1
                self.select_box.append(self.relics_attribute[i])
            else:
                self.select_box.append('%')
        if (all_num > 2):
            mg.showerror(title='错误', message='属性筛选条件不能超过两个')
            for i in range(self.attribute_len):
                self.retrieval[i].deselect()	
        else:
            self.update_select(style)
            self.relics_filter_win.withdraw()#隐藏窗口
            
    
    #确认保存添加的圣遗物
    #TODO:将圣遗物信息插入relics表
    #finish
    def relics_save(self, style, event = None):
        attri_dic = {}
        attri_dic['id'] = self.data.get_newid()
        attri_dic['detailName'] = self.relics_addname_box.get()
        attri_dic['pos'] = self.relics_pos[attri_dic['detailName']]
        attri_dic['setName'] = self.relics_setname[attri_dic['detailName']]
        attri_dic['level'] = self.relics_addlevel_spin.get()
        attri_dic['mainTag_name'] = self.relics_mainname_box.get()
        attri_dic['mainTag_value'] = self.relics_mainvalue_entry.get()
        attri_dic['equipped'] = None
        for i in range(4):
            if (self.relics_sub_list[i]['show'] == True):
                attri_dic['Tag_name' + str(i)] = self.relics_sub_list[i]['relics_subname_box'].get()
                attri_dic['Tag_value' + str(i)] = self.relics_sub_list[i]['relics_subvalue_entry'].get()
            else:
                attri_dic['Tag_name' + str(i)] = False
                attri_dic['Tag_value' + str(i)] = False
        self.add_button_Cmd(attri_dic, style)
        self.relics_add_win.withdraw()
        #将圣遗物信息加入数据库
        self.data.insert_relics(attri_dic)
    
    #装备圣遗物
    def relics_up(self, ID, num, pos, style, event = None):
        #圣遗物装配窗口
        self.relics_up_win = tk.Toplevel()
        self.relics_up_win.title("选择角色装配圣遗物")
        self.relics_up_win.geometry('200x100+200+100')
        self.relics_up_win.iconbitmap("E:/picture/hutao512.ico")
        self.select_char_box = Combobox(self.relics_up_win)
        select_character_list = []
        for i in range(len(self.assemble_list)):
            if self.assemble_list[i]['assemble_' + pos + '_text'].get() == " ":
                select_character_list.append(self.assemble_list[i]['character_name'])
        self.select_char_box['value'] = select_character_list
        self.select_char_box.pack(side = 'top', padx = 20, pady = 16)
        #提交按钮
        style.configure('select_char_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.select_char_button = Button(self.relics_up_win, text='确认', command=lambda:self.relics_up_chara(ID, num), style='select_char_button.TButton',cursor = 'hand2')
        self.select_char_button.pack(side = 'right', padx = 8)
        #当前的装配表中没有角色时不可点击
        if len(select_character_list) == 0:
            self.select_char_button.config(state=tk.DISABLED)
        else:
            #设置下拉菜单选项的默认值
            self.select_char_box.current(0)
        
    
    #装配界面显示圣遗物
    def assemble_relics_visable(self, i, detailName, pos):
        #改图片,图片必须是全局变量
        self.assemble_list[i][pos + '_pic'] = tk.PhotoImage(file = 'E:/picture/relics/' + detailName + '.png' )
        self.assemble_list[i][pos + '_pic'] = self.assemble_list[i][pos + '_pic'].subsample(2,2)
        self.assemble_list[i]['assemble_' + pos].config(image = self.assemble_list[i][pos + '_pic'])
        #改名字
        self.assemble_list[i]['assemble_' + pos + '_text'].set(detailName)
        #显示卸载按钮
        if pos == 'flower':
            self.assemble_list[i]['assemble_' + pos + '_dele'].grid(row = 2, column = 2, sticky = 'n', pady = 2)
        elif pos == 'feather':
            self.assemble_list[i]['assemble_' + pos + '_dele'].grid(row = 2, column = 3, sticky = 'n', pady = 2)
        elif pos == 'sand':
            self.assemble_list[i]['assemble_' + pos + '_dele'].grid(row = 2, column = 4, sticky = 'n', pady = 2)
        elif pos == 'cup':
            self.assemble_list[i]['assemble_' + pos + '_dele'].grid(row = 2, column = 5, sticky = 'n', pady = 2)
        elif pos == 'head':
            self.assemble_list[i]['assemble_' + pos + '_dele'].grid(row = 2, column = 6, sticky = 'n', pady = 2)
    
    #圣遗物装配提交按钮
    #TODO：到数据库relics表更新装配信息，需要传入id号 
    #finfsh
    def relics_up_chara(self, ID, num, event = None):
        character_name = self.select_char_box.get()
        #更新数据库
        self.data.update_equipped(ID, character_name)
        #位置
        pos = self.relics_pos[self.relic_list[num - 1]['detailName']]
        #此步骤进行后，角色不知道他装配了哪个圣遗物，只能得到圣遗物的名字和图片
        for i in range(len(self.assemble_list)):
            if self.assemble_list[i]['character_name'] == character_name:
                #隐藏圣遗物的装备和删除按钮，在角色界面卸载时，需要到数据库查询圣遗物号码，再查前端是否有该圣遗物，有的话再把按钮显示出来
                self.relic_list[num - 1]['formore_button'].place_forget()
                #改装配界面前端显示
                self.assemble_relics_visable(i, self.relic_list[num - 1]['detailName'], pos)
                #摧毁窗口
                self.relics_up_win.destroy()
                break        
    
    #删除圣遗物
    #TODO：从relics表中将记录删除
    #finish
    def formore_button_Cmd(self,ID, num,event=None):
        #从表中删除记录
        self.data.dele_single_relic(ID)
        self.relic_list[num - 1]['Frame'].destroy()
        for i in range(len(self.relic_list) - num):
            self.relic_list[i + num]['num'] -= 1
            if (self.relic_list[i + num]['grid_column'] == 0):
                self.relic_list[i + num]['grid_column'] = 3
                self.relic_list[i + num]['grid_row'] -= 1
            else:
                self.relic_list[i + num]['grid_column'] -= 1
            self.relic_list[i + num]['Frame'].grid(row = self.relic_list[i + num]['grid_row'],column = self.relic_list[i + num]['grid_column'], sticky = "w",padx = 10, pady = 10)
        self.relic_list.pop(num - 1)
        
    #清空圣遗物
    #TODO:获取圣遗物的id，在后端删除
    #finish
    def dele_option_Cmd(self,event=None):
        for i in range(len(self.relic_list)):
            #从数据库中删除记录
            self.data.dele_single_relic(self.relic_list[i]['id'])
            #从界面上删除记录
            self.relic_list[i]['Frame'].destroy()
        self.relic_list.clear() 
        
    #武器界面
    def weapon_Interface(self,style):
        self.weapon_Frame1 = tk.LabelFrame(self.top, text='', background='#e0ffcf', font=('宋体',9))
        self.weapon_Frame3 = tk.LabelFrame(self.top, text='',font=('宋体',9),bg = '#FFFFFF')
        
        self.weapon_title = tk.Label(self.weapon_Frame1, anchor = 'n', text = '武器图鉴', font = ('微软雅黑', 20, 'bold'), bg = '#e0ffcf')
        self.weapon_title.place(relx = 0.03, rely = 0.2)
        
        #存放武器的总框架
        #画布用来使框架Frame4框架滚动
        self.canvas_3 = tk.Canvas(self.weapon_Frame3)
        self.canvas_3.place(relx=0., rely=0., relwidth=0.984, relheight=1)
        self.VScroll_3 = tk.Scrollbar(self.weapon_Frame3,orient="vertical",command=self.canvas_3.yview)
        self.VScroll_3.pack(side='right',fill='y')
        self.canvas_3.configure(yscrollcommand=self.VScroll_3.set) #绑定滚动条和画布
        self.weapon_Frame4 = tk.Frame(self.canvas_3)
        self.weapon_Frame4.pack(fill = 'both')
        self.canvas_3.create_window((0,0),window = self.weapon_Frame4, anchor="nw")
        self.weapon_Frame4.bind("<Configure>",self.change_VScroll_3) #绑定框架和滚动条

        self.weapon_frame = tk.Frame(self.weapon_Frame3, bg = '#bd8b56')
        self.weapon_frame.place(relx=0.583, rely=0, relwidth=0.4, relheight=1)
        self.weapon_name_frame = tk.Frame(self.weapon_frame, bg = '#bb6832')
        self.weapon_name_frame.place(relx = 0, rely = 0, relwidth=1, relheight=0.08)
        #武器名称
        self.weapon_name_text = tk.StringVar()
        self.weapon_name_text.set("  ")
        
        self.weapon_name_label = tk.Label(self.weapon_frame, bg = '#bb6832', anchor = 'w', textvariable = self.weapon_name_text, fg = 'white', font = ('微软雅黑', 20, 'bold'))
        self.weapon_name_label.grid(row = 0, column = 0, padx = 10)
        self.weapon_blank_frame = tk.Frame(self.weapon_frame, bg = '#bd8b56')
        self.weapon_blank_frame.grid(row = 1, column = 0, pady = 12)
        self.weapon_pos_label = tk.Label(self.weapon_frame,text = '武器',  fg = '#FFFFFF',anchor = 'w', bg = '#bd8b56', font = ('宋体', 12, 'bold'))
        self.weapon_pos_label.grid(row = 2, column = 0, padx = 16, pady = 1, sticky = 'w')
        #属性
        self.Properties_text = tk.StringVar()
        self.Properties_text.set("")
        
        self.Properties_label = tk.Label(self.weapon_frame,textvariable = self.Properties_text,  fg = '#d3c6c0',anchor = 'w', bg = '#bd8b56', font = ('宋体', 12, 'bold'))
        self.Properties_label.grid(row = 3, column = 0, padx = 15, pady = 1,sticky = 'w')
        #属性值
        self.Properties_value_text = tk.StringVar()
        self.Properties_value_text.set("")
        
        self.Properties_value_label = tk.Label(self.weapon_frame,textvariable = self.Properties_value_text,  fg = '#FFFFFF',anchor = 'w', bg = '#bd8b56', font = ('宋体', 13, 'bold'))
        self.Properties_value_label.grid(row = 4, column = 0, padx = 17, sticky = 'w', pady = 1)
        self.attack_label = tk.Label(self.weapon_frame,text = '基础攻击力',  fg = '#d3c6c0',anchor = 'w', bg = '#bd8b56', font = ('宋体', 12, 'bold'))
        self.attack_label.grid(row = 5, column = 0, padx = 15, sticky = 'w', pady = 1)
        #攻击力数值
        self.attack_value_text = tk.StringVar()
        self.attack_value_text.set("")
        
        self.attack_value_label = tk.Label(self.weapon_frame,textvariable = self.attack_value_text,  fg = '#FFFFFF',anchor = 'w', bg = '#bd8b56', font = ('宋体', 24, 'bold'))
        self.attack_value_label.grid(row = 6, column = 0, padx = 17, sticky = 'w', pady = 1)
        #图片
        self.weapon_big_pic = tk.PhotoImage( file = "")
        #self.weapon_big_pic = self.weapon_big_pic.subsample(1,1)
        
        self.weapon_big_pic_label = tk.Label(self.weapon_frame, image = self.weapon_big_pic, bg = '#FFFFFF')
        self.weapon_big_pic_label.place(relx = 0.5, rely = 0.08, relwidth=0.5, relheight=0.35)
        
        self.weapon_skill_frame = tk.Frame(self.weapon_frame, bg = '#ece4d7')
        self.weapon_skill_frame.place(relx = 0, rely = 0.43, relwidth=1, relheight=0.6)
        #说明
        self.weapon_skill_text = tk.StringVar()
        self.weapon_skill_text.set("")
        
        self.weapon_skill_label = tk.Message(self.weapon_skill_frame,anchor = 'w', fg = '#4c5363', bg = '#ece4d7',  font = ('宋体', 11), textvariable = self.weapon_skill_text)
        self.weapon_skill_label.place(relx = 0.12, rely = 0.09, relwidth=0.8, relheight=0.6)
              
    #添加武器
    def add_weapon(self, weapon_name):
        new_weapon = {}
        new_weapon['num'] = len(self.weapon_pic_list) + 1 #列表中的第几个元素

        new_weapon['Name'] = weapon_name
        new_weapon['pic'] = tk.PhotoImage( file = "E:/picture/weapon/" + weapon_name + ".png")
        new_weapon['pic'] = new_weapon['pic'].subsample(2,2)
        
        new_weapon['button'] = tk.Button(self.weapon_Frame4, image = new_weapon['pic'], bg = '#FFFFFF',relief = 'ridge', command = lambda:self.show_weapon_detail(new_weapon['num']),cursor = 'hand2') 
        new_weapon['row'] = (new_weapon['num'] - 1) // 4
        new_weapon['column'] = (new_weapon['num'] - 1) % 4

        new_weapon['button'].grid(row = new_weapon['row'], column = new_weapon['column'],padx = 10, pady = 10)
        self.weapon_pic_list.append(new_weapon)
    
    #展示武器面板信息
    def show_weapon_detail(self, num):

        weapon_detail = self.data.select_weapon_detail(self.weapon_pic_list[num - 1]['Name'])
        self.weapon_name_text.set(weapon_detail[0])
        self.Properties_text.set(weapon_detail[2])
        
        if weapon_detail[2] == '元素精通':
            self.Properties_value_text.set(str(weapon_detail[3]))
        else:
            self.Properties_value_text.set(str(round(weapon_detail[3] * 100,1)) + '%')
            
        self.attack_value_text.set(weapon_detail[1])
        self.weapon_skill_text.set(weapon_detail[4])
        
        self.weapon_big_pic = tk.PhotoImage(file = "E:/picture/weapon/" + weapon_detail[0] + ".png")
        self.weapon_big_pic = self.weapon_big_pic.subsample(1,1)
        self.weapon_big_pic_label.config(image = self.weapon_big_pic)
        
    #人物界面
    def character_interface(self, style):
        self.assemble_Frame1 = tk.LabelFrame(self.top, text='', background='#e0ffcf', font=('宋体',9))
        self.assemble_Frame3 = tk.LabelFrame(self.top, text='',font=('宋体',9),bg = '#FFFFFF')
        self.assemble_title = tk.Label(self.assemble_Frame1, anchor = 'n', text = '角色装配模拟', font = ('微软雅黑', 20, 'bold'), bg = '#e0ffcf')    
        self.assemble_title.place(relx = 0.03, rely = 0.2)
        #清空按钮
        style.configure('assemble_dele_option.TButton',background='#FFFFFF', font=('宋体',9))
        self.assemble_dele_option = Button(self.assemble_Frame1, text='清空', command=lambda:self.assemble_dele_option_Cmd(style), style='assemble_dele_option.TButton',cursor = 'hand2')
        self.assemble_dele_option.place(relx=0.624, rely=0.18, relwidth=0.058, relheight=0.461)
        #添加人物按钮
        style.configure('assemble_add_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.assemble_add_button = Button(self.assemble_Frame1, text='+ 添加', command = self.assemble_add_character, style='assemble_add_button.TButton',cursor = 'hand2')
        self.assemble_add_button.place(relx=0.531, rely=0.18, relwidth=0.058, relheight=0.461)
        #画布用来使框架滚动
        self.canvas_2 = tk.Canvas(self.assemble_Frame3, bg = '#FFFFFF')
        self.canvas_2.place(relx=0., rely=0., relwidth=0.984, relheight=1)
        #界面滚动条
        self.VScroll_2 = tk.Scrollbar(self.assemble_Frame3,orient="vertical",command=self.canvas_2.yview)
        self.VScroll_2.pack(side='right',fill='y')
        self.canvas_2.configure(yscrollcommand=self.VScroll_2.set) #绑定滚动条和画布
        #存放框架,在画布上创建
        self.assemble_Frame4 = tk.Frame(self.canvas_2, bg = '#FFFFFF')
        self.assemble_Frame4.pack()
        #将Frame4添加到canvas_1上
        self.canvas_2.create_window((0,0),window = self.assemble_Frame4, anchor="nw")
        self.assemble_Frame4.bind("<Configure>",self.change_VScroll_2) #绑定框架和滚动条
        #人物添加窗口
        self.assemble_up_win = tk.Toplevel()
        self.assemble_up_win.title("选择角色")
        self.assemble_up_win.geometry('200x100+200+100')
        self.assemble_up_win.iconbitmap("E:/picture/hutao512.ico")
        self.select_character_box = Combobox(self.assemble_up_win)
        self.select_character_box['value'] = self.character_list
        self.select_character_box.pack(side = 'top', padx = 20, pady = 16)
        #设置下拉菜单选项的默认值
        self.select_character_box.current(0)
        #提交按钮
        style.configure('select_character_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.select_character_button = Button(self.assemble_up_win, text='确认', command=lambda:self.add_character_button(style) , style='select_character_button.TButton',cursor = 'hand2')
        self.select_character_button.pack(side = 'right', padx = 8)
        self.assemble_up_win.protocol("WM_DELETE_WINDOW", self.assemble_up_win.withdraw)
        self.assemble_up_win.withdraw()

    #添加人物框架
    def add_character_frame(self, character_name, style, event = None):
        character_dic = {}
        character_dic['num'] = len(self.assemble_list) + 1 #第几个人物
        #人物装配框架
        character_dic['Frame'] = tk.Frame(self.assemble_Frame4, bg = '#d0ffea', height = 110, width = 800)
        character_dic['Frame'].pack(side = 'top', padx = 20, pady = 10)
        space = 23
        #人物名称
        character_dic['character_name'] = character_name
        #人物按钮
        character_dic['assemble_shenli_pic'] = tk.PhotoImage(file = "E:/picture/character/" + character_dic['character_name'] + '.png')
        character_dic['assemble_shenli_pic'] = character_dic['assemble_shenli_pic'].subsample(3,3)
        character_dic['assemble_character_button'] = tk.Button(character_dic['Frame'], command=lambda:self.look_detail(character_dic['character_name']), image = character_dic['assemble_shenli_pic'],bg = '#8080FF',activebackground = '#8080FF',cursor = 'hand2')
        character_dic['assemble_character_button'].grid(row = 0, column = 0, sticky = 'w', padx = space)
        #人物名称label
        character_dic['assemble_char_label'] = tk.Label(character_dic['Frame'], text = character_dic['character_name'], font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['assemble_char_label'].grid(row = 1, column = 0, sticky = 'n')
        #武器按钮
        character_dic['assemble_weapon_button'] = tk.Button(character_dic['Frame'], text='+', width = 3 ,font = ('微软雅黑', 12,'bold'), command=lambda:self.assemble_weapon(character_dic['num'],style) ,bg = '#FFFFFF',activebackground = '#8080FF',cursor = 'hand2')
        character_dic['assemble_weapon_button'].grid(row = 0, column = 1, sticky = 'w', padx = space, ipadx = 8, ipady = 8)
        #武器名称label
        character_dic['assemble_weapon_text'] = tk.StringVar()
        character_dic['assemble_weapon_text'].set("武器")
        character_dic['assemble_weapon_label'] = tk.Label(character_dic['Frame'], textvariable=  character_dic['assemble_weapon_text'],font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['assemble_weapon_label'].grid(row = 1, column = 1, sticky = 'n')
        #武器卸载按钮
        character_dic['assemble_weapon_dele'] = tk.Button(character_dic['Frame'], text='卸载', width = 4 ,font = ('微软雅黑', 9,'bold'),  command=lambda:self.assemble_weapon_dele(character_dic['num']) ,bg = '#FFFFFF',activebackground = '#8080FF',cursor = 'hand2')
        #flower label
        character_dic['assemble_flower'] = tk.Label(character_dic['Frame'], text = 'flower',font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['assemble_flower'].grid(row = 0, column = 2, sticky = 'w', padx = space, ipadx = 13, ipady = 15)
        character_dic['assemble_flower_text'] = tk.StringVar()
        character_dic['assemble_flower_text'].set(" ")
        #flower text
        character_dic['flower_text'] = tk.Label(character_dic['Frame'], textvariable = character_dic['assemble_flower_text'],font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['flower_text'].grid(row = 1, column = 2,sticky = 'n')
        #flower卸载
        character_dic['assemble_flower_dele'] = tk.Button(character_dic['Frame'], text='卸载', width = 4 ,font = ('微软雅黑', 9,'bold'),  command=lambda:self.assemble_relics_dele(character_dic['num'], 'flower', style) ,bg = '#FFFFFF',activebackground = '#8080FF',cursor = 'hand2')
        #feather label
        character_dic['assemble_feather'] = tk.Label(character_dic['Frame'],text = 'feather',font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['assemble_feather'].grid(row = 0, column = 3, sticky = 'w', padx = space, ipadx = 13, ipady = 15)
        #feather_text
        character_dic['assemble_feather_text'] = tk.StringVar()
        character_dic['assemble_feather_text'].set(" ")
        character_dic['feather_text'] = tk.Label(character_dic['Frame'], textvariable = character_dic['assemble_feather_text'],font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['feather_text'].grid(row = 1, column = 3,sticky = 'n')   
        #feather卸载
        character_dic['assemble_feather_dele'] = tk.Button(character_dic['Frame'], text='卸载', width = 4 ,font = ('微软雅黑', 9,'bold'),  command=lambda:self.assemble_relics_dele(character_dic['num'], 'feather', style) ,bg = '#FFFFFF',activebackground = '#8080FF',cursor = 'hand2')
        #sand label
        character_dic['assemble_sand'] = tk.Label(character_dic['Frame'],text = 'sand',font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['assemble_sand'].grid(row = 0, column = 4, sticky = 'w', padx = space, ipadx = 13, ipady = 15)
        #sand text
        character_dic['assemble_sand_text'] = tk.StringVar()
        character_dic['assemble_sand_text'].set(" ")
        character_dic['sand_text'] = tk.Label(character_dic['Frame'], textvariable = character_dic['assemble_sand_text'],font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['sand_text'].grid(row = 1, column = 4,sticky = 'n')
        #sand卸载
        character_dic['assemble_sand_dele'] = tk.Button(character_dic['Frame'], text='卸载', width = 4 ,font = ('微软雅黑', 9,'bold'),  command=lambda:self.assemble_relics_dele(character_dic['num'], 'sand', style) ,bg = '#FFFFFF',activebackground = '#8080FF',cursor = 'hand2')
        #cup label
        character_dic['assemble_cup'] = tk.Label(character_dic['Frame'], text = 'cup',font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['assemble_cup'].grid(row = 0, column = 5, sticky = 'w', padx = space, ipadx = 13, ipady = 15)
        #cup text
        character_dic['assemble_cup_text'] = tk.StringVar()
        character_dic['assemble_cup_text'].set(" ")
        character_dic['cup_text'] = tk.Label(character_dic['Frame'], textvariable = character_dic['assemble_cup_text'],font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['cup_text'].grid(row = 1, column = 5,sticky = 'n') 
        #cup卸载
        character_dic['assemble_cup_dele'] = tk.Button(character_dic['Frame'], text='卸载', width = 4 ,font = ('微软雅黑', 9,'bold'),  command=lambda:self.assemble_relics_dele(character_dic['num'], 'cup', style) ,bg = '#FFFFFF',activebackground = '#8080FF',cursor = 'hand2')
        #head label
        character_dic['assemble_head'] = tk.Label(character_dic['Frame'], text = 'head',font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['assemble_head'].grid(row = 0, column = 6, sticky = 'w', padx = space, ipadx = 13, ipady = 15)
        #head text
        character_dic['assemble_head_text'] = tk.StringVar()
        character_dic['assemble_head_text'].set(" ")
        character_dic['head_text'] = tk.Label(character_dic['Frame'], textvariable = character_dic['assemble_head_text'],font = ('微软雅黑', 12,'bold'),bg ='#d0ffea')
        character_dic['head_text'].grid(row = 1, column = 6,sticky = 'n') 
        #head卸载
        character_dic['assemble_head_dele'] = tk.Button(character_dic['Frame'], text='卸载', width = 4 ,font = ('微软雅黑', 9,'bold'),  command=lambda:self.assemble_relics_dele(character_dic['num'], 'head', style) ,bg = '#FFFFFF',activebackground = '#8080FF',cursor = 'hand2')
        #右上角...
        character_dic['formore_button'] = tk.Menubutton(character_dic['Frame'], text='...', relief = 'ridge',activebackground = '#d0ffea',font=('宋体',10,'bold'),bg = '#d0ffea',bd = 0, cursor = 'hand2')
        character_dic['filemenu']=tk.Menu(character_dic['formore_button'],tearoff = False)
        character_dic['filemenu'].add_command(label = '删除',command = lambda:self.assemble_formore_button_Cmd(character_dic['num'], style))
        character_dic['formore_button'].place(relx=0.92, rely=0, relwidth=0.13, relheight=0.08)
        character_dic['formore_button'].config(menu = character_dic['filemenu'])
        self.assemble_list.append(character_dic)
        self.assemble_up_win.withdraw()
    
    #添加角色按钮
    def add_character_button(self,style, event = None):
        #拿到人物名称
        character_name = self.select_character_box.get()
        #名称插入数据库
        self.data.insert_character(character_name)
        #前端显示角色信息
        self.add_character_frame(character_name, style)
    
    #查询角色详细面板信息按钮
    #TODO：到视图查询人物属性
    #finish
    def look_detail(self, character_name, event = None):
        #到视图查询角色面板数值
        panel = self.data.select_panel(character_name)
        ##查看人物属性面板窗口
        self.assemble_detail_win = tk.Toplevel()
        self.assemble_detail_win.title("角色面板")
        self.assemble_detail_win.geometry('400x540+200+100')
        self.assemble_detail_win.iconbitmap("E:/picture/hutao512.ico")
        self.assemble_detail_win.attributes("-alpha",0.8)
        self.assemble_attribute_list = []
        for i in range(len(self.attribute_list)):
            if (i % 2 == 0):
                color = '#0c1319'
            else:
                color = '#02090f'
            attribute_frame = tk.Frame(self.assemble_detail_win, bg = color)
            attribute_name_label = tk.Label(attribute_frame,anchor = 'w',justify = tk.LEFT, text = self.attribute_list[i], bg = color, fg = 'white', font = ('微软雅黑', 11))
            if self.attribute_list[i] in self.relics_percentage:
                if self.attribute_list[i] == '元素充能效率':
                    panel_value = str(round(panel[i + 7] * 100)) + '%'
                else:
                    panel_value = str(round(panel[i + 7] * 100, 1)) + '%'
            else:
                panel_value = str(round(panel[i + 7]))
            attribute_value_label = tk.Label(attribute_frame, anchor = 'w', justify = tk.LEFT, text = panel_value, bg = color, fg = 'white', font = ('微软雅黑', 11))
            attribute_name_label.pack(side = 'left', padx = 5)
            attribute_value_label.pack(side = 'right', padx = 5)
            attribute_frame.pack(fill = tk.X, side = 'top', ipady = 5)
            self.assemble_attribute_list.append(attribute_frame)
    
    #在复选框中移除已有的角色
    def remove_character_box(self):
        character_box_list = self.character_list[:]
        for i in range(len(self.assemble_list)):
            character_box_list.remove(self.assemble_list[i]['character_name'])
        self.select_character_box['value'] = character_box_list
        self.select_character_box.current(0)      
    
    
    #装配界面添加角色,打开选择角色的窗口
    def assemble_add_character(self):
        self.remove_character_box()
        self.assemble_up_win.deiconify()	
    
    #武器装备按钮,无用
    def assemble_weapon(self, num, style, event = None):
        #武器装备窗口
        self.weapon_up_win = tk.Toplevel()
        self.weapon_up_win.title("选择武器进行装备")
        self.weapon_up_win.geometry('200x100+200+100')
        self.weapon_up_win.iconbitmap("E:/picture/hutao512.ico")
        self.select_weapon_box = Combobox(self.weapon_up_win)
        self.select_weapon_box['value'] = self.weapon_list
        self.select_weapon_box.pack(side = 'top', padx = 20, pady = 16)
        #设置下拉菜单选项的默认值
        self.select_weapon_box.current(0)
        #提交按钮
        style.configure('select_weapon_button.TButton',background='#FFFFFF', font=('宋体',9))
        self.select_weapon_button = Button(self.weapon_up_win, text='确认', command=lambda:self.weapon_up_commit(num), style='select_weapon_button.TButton',cursor = 'hand2')
        self.select_weapon_button.pack(side = 'right', padx = 8)
        self.weapon_up_win.protocol("WM_DELETE_WINDOW", self.weapon_up_win.withdraw)
    
    #装配界面显示武器信息
    def assemble_weapon_visable(self, i, weapon_name):
        self.assemble_list[i]['assemble_wuqie_pic'] = tk.PhotoImage( file = "E:/picture/weapon/" + weapon_name + ".png")
        self.assemble_list[i]['assemble_wuqie_pic'] = self.assemble_list[i]['assemble_wuqie_pic'].subsample(3,3)
        self.assemble_list[i]['assemble_weapon_label'] = tk.Label(self.assemble_list[i]['Frame'],image = self.assemble_list[i]['assemble_wuqie_pic'])
        self.assemble_list[i]['assemble_weapon_label'].grid(row = 0, column = 1, sticky = 'w', padx = 23)
        #显示武器卸载按钮
        self.assemble_list[i]['assemble_weapon_dele'].grid(row = 2, column = 1, sticky = 'n', pady = 2)
        self.assemble_list[i]['assemble_weapon_text'].set(weapon_name)
    
    #选择武器确认按钮,
    #TODO：向数据库更新角色武器装配信息
    #finish
    def weapon_up_commit(self, num, event = None):
        weapon_name = self.select_weapon_box.get()
        #数据库武器更新
        self.data.assemble_weapon(self.assemble_list[num - 1]['character_name'], weapon_name)
        #界面武器更新
        self.assemble_weapon_visable(num - 1, weapon_name)
        #窗口销毁
        self.weapon_up_win.destroy()

    #删除角色和其装配信息，
    #TODO:assemble表删除一个元组
    #TODO:查询relics表，更新前端圣遗物是否装配状态
    #finish
    def assemble_formore_button_Cmd(self, num, style, event = None):
        #从数据库中将记录删除
        self.data.assemble_dele(self.assemble_list[num - 1]['character_name'])
        #更新圣遗物显示装配状态
        self.update_select(style)
        #从前端将记录删除
        self.assemble_list[num - 1]['Frame'].destroy()
        for i in range(len(self.assemble_list) - num):
            self.assemble_list[i + num]['num'] -= 1
        self.assemble_list.pop(num - 1)
        
    #卸载武器
    #TODO:到数据库更改assemble表
    #finish
    def assemble_weapon_dele(self, num, event = None):
        #到数据库删除武器
        self.data.weapon_down(self.assemble_list[num - 1]['character_name'])
        #前端删除武器
        self.assemble_list[num - 1]['assemble_weapon_label'].destroy()
        self.assemble_list[num - 1]['assemble_weapon_dele'].grid_forget()
        self.assemble_list[num - 1]['assemble_weapon_text'].set('武器')    
        
    #装配界面圣遗物卸载按钮
    #TODO：改assemble表，并查询relics表更新前端圣遗物是否装配状态
    def assemble_relics_dele(self, num, pos, style, event = None):
        #到数据库中卸载圣遗物
        self.data.relics_down(self.assemble_list[num - 1]['character_name'], pos)
        #更新圣遗物显示装配状态
        self.update_select(style)
        #去掉图片
        self.assemble_list[num - 1]['assemble_' + pos].config(image = "")
        #去掉文字,注意用空格表示是否装备了圣遗物
        self.assemble_list[num - 1]['assemble_' + pos + '_text'].set(" ")
        #隐藏卸载按钮
        self.assemble_list[num - 1]['assemble_' + pos + '_dele'].grid_forget()

    #人物清空按钮
    #TODO:逐条DELETE assemble表,并查询relics表更新前端圣遗物是否装配状态
    def assemble_dele_option_Cmd(self, style, event = None):
        for i in range(len(self.assemble_list)):
            self.data.assemble_dele(self.assemble_list[i]['character_name'])
            self.assemble_list[i]['Frame'].destroy()
        self.assemble_list.clear()
        self.update_select(style)
    
    def Relics_button_Cmd(self,event=None):
        self.assemble_Frame1.place_forget()
        self.assemble_Frame3.place_forget()
        self.weapon_Frame1.place_forget()
        self.weapon_Frame3.place_forget()
        self.Frame1.place(relx=0.128, rely=-0.001, relwidth=1.23, relheight=0.160)
        self.Frame3.place(relx=0.128, rely=0.140, relwidth=0.874, relheight=0.865)
    
    def weapon_button_Cmd(self,event=None):
        self.assemble_Frame1.place_forget()
        self.assemble_Frame3.place_forget()
        self.Frame1.place_forget()
        self.Frame3.place_forget()
        self.weapon_Frame1.place(relx=0.128, rely=-0.001, relwidth=1.23, relheight=0.160)
        self.weapon_Frame3.place(relx=0.128, rely=0.140, relwidth=0.874, relheight=0.865)
        
    def character_button_Cmd(self,event=None):
        self.Frame1.place_forget()
        self.Frame3.place_forget()
        self.weapon_Frame1.place_forget()
        self.weapon_Frame3.place_forget()
        self.assemble_Frame1.place(relx=0.128, rely=-0.001, relwidth=1.23, relheight=0.160)
        self.assemble_Frame3.place(relx=0.128, rely=0.140, relwidth=0.874, relheight=0.865)
    
    def sel_button_Cmd(self,event=None):
        self.relics_filter_win.deiconify()

    #添加副词条按钮
    def relics_subadd(self,event = None):
        for i in range(4):
            if self.relics_sub_list[i]['show'] == False:
                self.relics_sub_list[i]['show'] = True
                self.relics_sub_list[i]['relics_sub_frame'].place(relx=0.3, rely=0.53 + i * 0.06)
                break
    #删除副词条按钮
    def relics_sub_dele(self, num, event = None):
        print(num)
        self.relics_sub_list[num]['show'] = False
        self.relics_sub_list[num]['relics_sub_frame'].place_forget()
    #绑定框架4和滚动条1
    def change_VScroll_1(self,event):
        self.canvas_1.configure(scrollregion=self.canvas_1.bbox("all"),width=200,height=200)
    def change_VScroll_2(self,event):
        self.canvas_2.configure(scrollregion=self.canvas_2.bbox("all"),width=200,height=200)
    def change_VScroll_3(self,event):
        self.canvas_3.configure(scrollregion=self.canvas_3.bbox("all"),width=200,height=200)

if __name__ == "__main__":
    G = gui()
    G.top.mainloop()
    G.data.close_conn()
    try: G.top.destroy()
    except: pass
